//
//  CardEditCellDelegate.m
//  Guazi
//
//  Created by koolearn on 11-6-5.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "CardEditCellDelegate.h"


@interface CardEditCellDelegate(private)
- (void) setValueByTextField:(UITextField*)textField;
@end



@implementation CardEditCellDelegate


@synthesize card;
@synthesize isNew;
@synthesize currentTextField;


- (id) init
{
	self = [super init];
	if ( self ) {
		self.currentTextField = nil;
	}
	return self;
}


- (NSString*) label:(NSInteger)tag
{
    if ( tag == kTagName ) {
        return @"姓名";
    }
    else if ( tag == kTagAddress ) {
        return @"地址";
    }
    else if ( tag == kTagCompony ) {
        return @"公司";
    }
    else if ( tag == kTagFax ) {
        return @"传真";
    }
    else if ( tag == kTagMobile ) {
        return @"手机";
    }
    else if ( tag == kTagPosition ) {
        return @"职务";
    }
    else if ( tag == kTagTel ) {
        return @"电话";
    }
    else if ( tag == kTagEmail ) {
        return @"邮箱";
    }
    else if ( tag == kTagPostcode ) {
        return @"邮编";
    }
    else {
        return @"label";
    }
}


- (NSString*) text:(NSInteger)tag
{
    if ( tag == kTagName ) {
        return card.name;
    }
    else if ( tag == kTagAddress ) {
        return card.address;
    }
    else if ( tag == kTagCompony ) {
        return card.company;
    }
    else if ( tag == kTagFax ) {
        return card.fax;
    }
    else if ( tag == kTagMobile ) {
        return card.mobile;
    }
    else if ( tag == kTagPosition ) {
        return card.position;
    }
    else if ( tag == kTagTel ) {
        return card.tel;
    }
    else if ( tag == kTagEmail ) {
        return card.email;
    }
    else if ( tag == kTagPostcode ) {
        return card.postcode;
    }
    else {
        return @"";
    }
}


- (CGFloat) labelWidth:(NSInteger)tag
{
    return 40.0f;
}


- (NSString*) textFieldPlaceHolder:(NSInteger)tag
{
    if ( tag == kTagName ) {
        return @"请输入姓名";
    }
    else if ( tag == kTagAddress ) {
        return @"请输入地址";
    }
    else if ( tag == kTagCompony ) {
        return @"请输入公司";
    }
    else if ( tag == kTagFax ) {
        return @"请输入传真";
    }
    else if ( tag == kTagMobile ) {
        return @"请输入手机";
    }
    else if ( tag == kTagPosition ) {
        return @"请输入职务";
    }
    else if ( tag == kTagTel ) {
        return @"请输入电话";
    }
    else if ( tag == kTagEmail ) {
        return @"请输入邮箱";
    }
    else if ( tag == kTagPostcode ) {
        return @"请输入邮编";
    }
    else {
        return @"请输入...";
    }
}


- (void)textFieldDidEndEditing:(UITextField *)textField
{
	[self setValueByTextField:textField];
}


- (void)textFieldDidBeginEditing:(UITextField *)textField
{
	self.currentTextField = textField;;
}


- (void) setValueByTextField:(UITextField*)textField
{
    NSInteger tag = textField.tag;
    if ( tag == kTagName ) {
        card.name = textField.text;
    }
    else if ( tag == kTagAddress ) {
        card.address = textField.text;
    }
    else if ( tag == kTagCompony ) {
        card.company = textField.text;
    }
    else if ( tag == kTagFax ) {
        card.fax = textField.text;
    }
    else if ( tag == kTagMobile ) {
        card.mobile = textField.text;
    }
    else if ( tag == kTagPosition ) {
        card.position = textField.text;
    }
    else if ( tag == kTagTel ) {
        card.tel = textField.text;
    }
    else if ( tag == kTagEmail ) {
        card.email = textField.text;
    }
    else if ( tag == kTagPostcode ) {
        card.postcode = textField.text;
    }
}


- (void) dealloc
{
    [card release];
	[currentTextField release];
    [super dealloc];
}

@end
